package com.jinzhi.jzweb.controller;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.jinzhi.common.annotation.Log;
import com.jinzhi.common.base.BaseController;
import com.jinzhi.common.utils.Result;
import com.jinzhi.jzweb.domain.MessagelogsDO;
import com.jinzhi.jzweb.service.MessagelogsService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * 
 * <pre>
 * 短信日志信息表
 * </pre>
 * <small> 2020-01-14 09:29:15 | lance</small>
 */
@Controller
@RequestMapping("/jzweb/messagelogs")
public class MessagelogsController extends BaseController {
	@Autowired
	private MessagelogsService messagelogsService;
	
	@GetMapping()
	@RequiresPermissions("jzweb:messagelogs:messagelogs")
	String Messagelogs(){
	    return "jzweb/messagelogs/messagelogs";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("jzweb:messagelogs:messagelogs")
	public Result<Page<MessagelogsDO>> list(MessagelogsDO messagelogsDTO){
        Wrapper<MessagelogsDO> wrapper = new EntityWrapper<MessagelogsDO>().orderBy("id", false);
        //wrapper.eq("name","jzweb");
        Page<MessagelogsDO> page = messagelogsService.selectPage(getPage(MessagelogsDO.class), wrapper);
        return Result.ok(page);
	}
	
	@GetMapping("/add")
	@RequiresPermissions("jzweb:messagelogs:add")
	String add(){
	    return "jzweb/messagelogs/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("jzweb:messagelogs:edit")
	String edit(@PathVariable("id") Long id,Model model){
		MessagelogsDO messagelogs = messagelogsService.selectById(id);
		model.addAttribute("messagelogs", messagelogs);
	    return "jzweb/messagelogs/edit";
	}
	
	@Log("添加短信日志信息表")
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("jzweb:messagelogs:add")
	public Result<String> save( MessagelogsDO messagelogs){
		messagelogsService.insert(messagelogs);
        return Result.ok();
	}
	
	@Log("修改短信日志信息表")
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("jzweb:messagelogs:edit")
	public Result<String>  update( MessagelogsDO messagelogs){
		boolean update = messagelogsService.updateById(messagelogs);
		return update ? Result.ok() : Result.fail();
	}
	
	@Log("删除短信日志信息表")
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("jzweb:messagelogs:remove")
	public Result<String>  remove( Long id){
		messagelogsService.deleteById(id);
        return Result.ok();
	}
	
	@Log("批量删除短信日志信息表")
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("jzweb:messagelogs:batchRemove")
	public Result<String>  remove(@RequestParam("ids[]") Long[] ids){
		messagelogsService.deleteBatchIds(Arrays.asList(ids));
		return Result.ok();
	}
	
}
